package com.web.controller;

import com.web.entity.*;
import com.web.service.DetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class DetailsController {
    @Autowired
    private DetailsService detailsService;
    @RequestMapping("/details")
    public List<Chargestock> list() {
        System.out.println("请求details");
        return detailsService.queryAllFromChargestock();

    }
    @RequestMapping("/search")
    public Chargestock search(int stockid) {
        System.out.println("请求search");
        return detailsService.queryFromChargestockById(stockid);}
    @RequestMapping("/update")
    public void update(int stockid){
        System.out.println("请求update");
        detailsService.updateStatusById(stockid);
    }
/*   @RequestMapping("/insert")
    public void insert(int id,String userid,String time,String description ,String phone) {
        Fixing fixing = new Fixing();
        fixing.setId(id);
        fixing.setUserid(userid);
        fixing.setTime(time);
        fixing.setDescription(description);
        fixing.setPhone(phone);
        detailsService.insertFixing(fixing);
        System.out.println(id);
    } */
    //插入报修表
    @PostMapping("/insert")
    public void insert(@RequestBody Fixing fixing) {
//        Fixing fixing = new Fixing();
//        fixing.setId(id);
//        fixing.setUserid(userid);
//        fixing.setTime(time);
//        fixing.setDescription(description);
//        fixing.setPhone(phone);

        System.out.println("请求insert");

        System.out.println(fixing.toString());
        detailsService.insertFixing(fixing);
    }
    //查看所有充电桩
    @RequestMapping("/fix")
    public List<Restore> fix()
    {
        System.out.println("请求fix");
        return detailsService.queryAllFromFixingJoinChargestock();
    }
    //处理维修，修改保报修表状态，插入维修表
    @PostMapping("/process")
    public void chuliweixiu(@RequestBody Weixiutable weixiutable)
    {
        System.out.println("请求process");
        System.out.println(weixiutable.toString());

        detailsService.updateStatusFromFixingByIdAndTime(weixiutable);
        detailsService.insertWeixiutable(weixiutable);

        //return null;
    }
    //查看维修表
    @RequestMapping("/query")
    public List<Weixiutable> queryAllFromWeixiutable()
    {
        System.out.println("请求query");

        return detailsService.queryAllFromWeixiutable();
        //return null;
    }
}
